<!DOCTYPE html>
<html >
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> 递归深拷贝 </title>
</head>
<body>
    <script>
        let arr = [1, 2, [3, 4], [5, 6], 7, [[8]]]
        let arr1 = [1, 2, [3, 4], [5, 6], 7, [[8]]]

        function copy(obj) {
            let newobj = null;
            if(typeof(obj) == 'object' && obj !== null) {
                newobj = obj instanceof Array? [] : {};
                for(var i in obj) {
                    newobj[i] = copy(obj[i])
                }
            } else {
                newobj = obj
            }

            return newobj
        }

        let newArr = copy(arr)
        console.log("拷贝之后：", newArr == arr, arr == arr1 )
    </script>
</body>
</html>